import Vue from 'vue'
import VueI18n from 'vue-i18n'
import Cookies from 'js-cookie'
import elementEnUSLocale from 'element-ui/lib/locale/lang/en' // element-ui lang
import elementZhCNLocale from 'element-ui/lib/locale/lang/zh-CN'// element-ui lang
import elementZhTWLocale from 'element-ui/lib/locale/lang/zh-TW'// element-ui lang
import enUSLocale from './en_US'
import zhCNLocale from './zh_CN'
import zhTWLocale from './zh_TW'

Vue.use(VueI18n)

const messages = {
  en_US: {
    ...enUSLocale,
    ...elementEnUSLocale
  },
  zh_CN: {
    ...zhCNLocale,
    ...elementZhCNLocale
  },
  zh_TW: {
    ...zhTWLocale,
    ...elementZhTWLocale
  }
}

const i18n = new VueI18n({
  // set locale
  // options: en or zh
  locale: Cookies.get('language') || 'en_US',
  // set locale messages
  messages
})

export default i18n
